import { BaseColumnsType, DiyProps } from "@/shared/components/table/typings";
import { ObjectType } from "@/shared/typings";
import { ReactNode } from "react";

export interface Response<T> {
  code: number;
  message: {
    description: string;
    detail: any;
  };
  response: T;
}

/** TODO */
export interface UpdateListRequest<T> {
  [x: string]: T;
}

/** 兼容服务端具名类型(比如 warehouse_ids)，方便后期其他分类使用 */
export interface BatchDeleteRequest {
  query: {
    [x: string]: string[];
    paging: any;
  };
}

export interface BatchUpdateStateRequest {
  filter?: {
    [x: string]: string[];
    paging: any;
  };
  new_state?: number;
}

export interface BatchResponse {
  task_id?: string;
}

export interface TableProps<T extends ObjectType> {
  title: string;
  /**适配字段 分类查询表格数据的id */
  currentId: string;
  /** 查询关联表格数据的id的key值， 因为服务端提交，返回的是按模块的具名字段(不一样) warehouse_id product_id等 所以做了后面一些变量Key 接口类型也要去变，服务端统一就好了 烦哦*/
  queryListIdKey?: string;
  /** 表格行节点id的key值 用于操作栏，编辑删除等 */
  nodeIdKey?: string;
  /** 批量操作的键 */
  batchSubmitKey?: string;
  submitKey?: string;
  /** 渲染表格columns */
  columns: BaseColumnsType<T>;
  /** 表格列表查询 */
  listApi: () => void;
  /** 操作：单个启用，禁用 */
  updateList: (data: any) => Promise<any>;
  /** 异步任务，批量启用，禁用 */
  // batchDeleteApi: (data: BatchDeleteWarehouseRequest) => Promise<Response<BatchDeleteWarehouseResponse>>;
  batchDeleteApi: (
    data: BatchDeleteRequest
  ) => Promise<Response<BatchResponse>>;
  /** 异步任务，批量删除 */
  batchUpdateApi: (
    data: BatchUpdateStateRequest
  ) => Promise<Response<BatchResponse>>;
  /** 模块新开页面标记，不跳转页面不需要 */
  moduleKey: string;
  diyConfig?: DiyProps;
  action: ObjectType;
}

export interface TableReturn {
  /** 渲染实体 */
  renderRelationTable: ReactNode;
}
